package com.fallsvc.dayproblem.demo202511;

import java.util.*;

/**
 * @auther falls_vc
 * description:
 * @date 2025/11/21  14:26
 */
public class Demo20251121 {
//    https://leetcode.cn/problems/roman-to-integer/description/?envType=study-plan-v2&envId=top-interview-150
//    罗马数字转整数

    Map<Character, Integer> symbolValues = new HashMap<Character, Integer>() {{
        put('I', 1);
        put('V', 5);
        put('X', 10);
        put('L', 50);
        put('C', 100);
        put('D', 500);
        put('M', 1000);
    }};

    public int romanToInt(String ss) {

        char[] s = ss.toCharArray();
        int sum = 0;
        for(int i = 0;i < s.length;i++) {
            int indexV = symbolValues.get(s[i]);
            if(i + 1 < s.length) {
                int nextV = symbolValues.get(s[i + 1]);
                if(indexV < nextV) {
                    sum -= indexV;
                }else {
                    sum += indexV;
                }
            }else {
                sum += indexV;
            }
        }
        return sum;
    }
    public int romanToInt1(String ss) {

        char[] s = ss.toCharArray();
        int sum = 0;
        for(int i = 0;i < s.length;i++) {
            int indexV = symbolValues.get(s[i]);

            int nextV = i + 1 < s.length ? symbolValues.get(s[i + 1]) : 0;
            if(indexV < nextV) {
                sum -= indexV;
            }else {
                sum += indexV;
            }

        }
        return sum;
    }

    public static void main(String[] args) {

        String a = "a";
        System.out.println(a.charAt(1));
//        int size = 2;
//        while (--size > 0) {
//            System.out.println("hh");
//        }
    }
    class Node {
        public int val;
        public List<Node> children;

        public Node() {}

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    }

//    https://leetcode.cn/problems/n-ary-tree-level-order-traversal/
//    N叉树的层序遍历
    public List<List<Integer>> levelOrder(Node root) {
        List<List<Integer>> ret=new ArrayList<>();
        if(root==null) return ret;
        Queue<Node> q = new LinkedList<>();
        q.offer(root);

        while(!q.isEmpty()) {
            List<Integer> tmp = new ArrayList<>();
            int size = q.size();
            while(size-- > 0) {
                Node node = q.poll();
                tmp.add(node.val);
                for(int i = 0;i < node.children.size();i++) {
                    q.offer(node.children.get(i));
                }
            }
            ret.add(tmp);
        }

        return ret;
    }

    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
//    https://leetcode.cn/problems/binary-tree-right-side-view/
    // 二叉树的右视图

    public List<Integer> rightSideView(TreeNode root) {

        List<Integer> ret = new ArrayList<>();
        if (root == null) return ret;


        Queue<TreeNode> q = new LinkedList<>();
        q.offer(root);
        while (!q.isEmpty()) {
            ret.add(q.peek().val);
            // 从右层序添加
            int size = q.size();
            while (size-- > 0) {
                TreeNode node = q.poll();
                if (node.right != null) {
                    q.offer(node.right);
                }
                if (node.left != null) {
                    q.offer(node.left);
                }
            }
        }
        return ret;
    }
}
